package net.admin.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.admin.db.item.ItemBean;
import net.admin.db.item.ItemDAO;

public class ItemBuyAction implements Action {
	         
	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ActionForward af = new ActionForward();
		af.setRedirect(false);
		boolean result=false;
		ItemDAO dao = null;
		af.setPath("/admin/item/item_regist_manage.jsp");
		
		HttpSession session = request.getSession();
		String admin_id=(String)session.getAttribute("user_id");
		String cust_nm = request.getParameter("cust_nm");
		String corp_no = request.getParameter("corp_no");
		String category_nm = request.getParameter("category_nm");
		String item_nm = request.getParameter("item_nm");
		String item_cd = request.getParameter("item_cd");
		String size = request.getParameter("size");
		String color = request.getParameter("color");
		String buy_cnt = request.getParameter("buy_cnt");
		int single_amount = Integer.parseInt(request.getParameter("single_amt"));
		System.out.println("item_cd : " + item_cd);
		String test = request.getParameter("test");
		System.out.println("test : " + test);
		System.out.println("size : " + size);
		System.out.println("item_nm : " + item_nm);
		System.out.println();
		ItemBean ib = new ItemBean();
		ib.setReg_id(admin_id);
		ib.setCorp_no(corp_no);
		ib.setCategory_nm(category_nm);
		ib.setName(item_nm);
		ib.setCode(item_cd);
		ib.setSize(size);
		ib.setColor(color);
		ib.setBuy_cnt(buy_cnt);
		ib.setAmount(single_amount);
		ib.setCust_name(cust_nm);
		request.setAttribute("input", ib);
		try{
			dao = new ItemDAO();
			result=dao.buyItem(ib);
			if(result==false){
				request.setAttribute("input", ib);
			}
			request.setAttribute("result", result==true?"Y":"N");
		}catch(Exception e){
			request.setAttribute("result", "N");
			e.printStackTrace();
		}finally{
			dao.close();
		}
		
		return af;
	}

}
